#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "wallyingLib.h"

static FILE *fp = NULL;
static char file_name[1024] = {0x00};
static uint32_t file_length = 0;

int main(int argc, char *argv[])
{
    printf("Hello World!\r\n");

    if (argc < 2) {
        system("pause");
        return 1;
    }

    strncpy(file_name, (char *)argv[1], sizeof(file_name));
    if ((fp = fopen(file_name, "wb")) == NULL) {
        printf(" ERROR: open file fail!!!\r\n");
        system("pause");
        return 1;
    }

    sscanf((char *)argv[2], "%d", &file_length);


    int32_t random;
    for (uint32_t i = 0; i < file_length; i++)
    {
        random = rand_number(0x00, 0xFF);
        fwrite(&random, 1, 1, fp);
    }

    printf("Generate %d-byte random file OK!!!\r\n", file_length);

    fclose(fp);

    system("pause");
    return 0;
}
